package com.wujilin.okra.adapter;

import static com.wujilin.okra.Okra.getLayoutInflater;
import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.wujilin.okra.R;
import com.wujilin.okra.database.ModelCursor;
import com.wujilin.okra.model.Model;

public class CategoryListAdapter extends CursorAdapter {
	private ModelCursor cursor;
	
	public CategoryListAdapter(Context context, ModelCursor cursor) {
		super(context, cursor, 0);
		this.cursor = cursor;
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		return getLayoutInflater(context).inflate(R.layout.list_item_category, parent, false);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		TextView nameText = (TextView) view.findViewById(R.id.category_name);
		TextView countText = (TextView) view.findViewById(R.id.category_count);
		Model category = this.cursor.getModel();
		String name = category.getString("name");
		String count = category.getString("count");
		nameText.setText(name);
		countText.setText(count);		
	}
}
